package com.atguigu.lease.web.admin.custom.converter;

import com.atguigu.lease.model.enums.ReleaseStatus;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

/**
 * projectName: com.atguigu.lease.web.admin.custom.converter
 *
 * @author: 赵伟风
 * description:
 */
//@Component
public class StringToReleaseStatusConverter implements Converter<String, ReleaseStatus> {

    @Override
    public ReleaseStatus convert(String source) {
//        if (source.equals("1")) return ReleaseStatus.RELEASED;
//        if (source.equals("0")) return ReleaseStatus.NOT_RELEASED;

        for (ReleaseStatus releaseStatus : ReleaseStatus.values()) {
            if (source.equals(releaseStatus.getCode()+"")){
                return releaseStatus;
            }
        }
        throw new RuntimeException("类型值必须是0或者1！！");
    }
}
